package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.KingBdOrganization;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.KingBdWu;
import com.ruoyi.system.service.IKingBdWuService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物料Controller
 * 
 * @author ruoyi
 * @date 2021-04-28
 */
@RestController
@RequestMapping("/system/wu")
public class KingBdWuController extends BaseController
{
    @Autowired
    private IKingBdWuService kingBdWuService;

    /**
     * 查询物料列表
     */
    @PreAuthorize("@ss.hasPermi('system:wu:list')")
    @GetMapping("/list")
    public TableDataInfo list(KingBdWu kingBdWu)
    {
        startPage();
        List<KingBdWu> list = kingBdWuService.selectKingBdWuList(kingBdWu);
        return getDataTable(list);
    }

    /**
     * 导出物料列表
     */
    @PreAuthorize("@ss.hasPermi('system:wu:export')")
    @Log(title = "物料", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(KingBdWu kingBdWu)
    {
        List<KingBdWu> list = kingBdWuService.selectKingBdWuList(kingBdWu);
        ExcelUtil<KingBdWu> util = new ExcelUtil<KingBdWu>(KingBdWu.class);
        return util.exportExcel(list, "wu");
    }

    /**
     * 获取物料详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:wu:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(kingBdWuService.selectKingBdWuById(id));
    }

    /**
     * 新增物料
     */
    @PreAuthorize("@ss.hasPermi('system:wu:add')")
    @Log(title = "物料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KingBdWu kingBdWu)
    {
        return toAjax(kingBdWuService.insertKingBdWu(kingBdWu));
    }

    /**
     * 修改物料
     */
    @PreAuthorize("@ss.hasPermi('system:wu:edit')")
    @Log(title = "物料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KingBdWu kingBdWu)
    {
        return toAjax(kingBdWuService.updateKingBdWu(kingBdWu));
    }

    /**
     * 删除物料
     */
    @PreAuthorize("@ss.hasPermi('system:wu:remove')")
    @Log(title = "物料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(kingBdWuService.deleteKingBdWuByIds(ids));
    }

    @CrossOrigin
    @PostMapping("/getCanglist")
    @ResponseBody
    public String getCanglist(@RequestBody KingBdOrganization kingBdOrganization){
        if(StringUtils.isNotEmpty(kingBdOrganization.getfName())) {
            return   kingBdWuService.getWuLists(kingBdOrganization.getfName());
        }else {
            return "";
        }
    }
}
